home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 October / macformat-029.iso / mac / Shareware City / HyperCard / CapsLock / CapsLock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-11  |  1.6 KB  |  74 lines  |  [TEXT/KAHL]

  1. /*
  2.  *    CapsLock.c
  3.  *
  4.  *    By Theron Trowbridge
  5.  *    © 1995, all rights reserved
  6.  *
  7.  *    A XFCN for HyperCard to determine if the Caps Lock key is down or not.
  8.  *    Takes no parameters.  Returns "down" if the Caps Lock key is down, "up" if it is not.
  9.  *
  10.  *    If there is one or more parameters, and the first one is a "?", syntax info is returned.
  11.  *    If there is one or more parameters, and the first one is a "!", copyright info is returned.
  12.  *
  13.  */
  14.  
  15. #include "HyperXCmd.h"
  16. #include "XCmdStuff.h"
  17.  
  18. Boolean    CapsLockIsDown( void );
  19.  
  20.  pascal void main( XCmdPtr paramPtr )
  21. {
  22.     char        *paramString;
  23.     short        numParams, paramLength;
  24.     char        paramChar;
  25.     
  26.     /********    Do the standard XCMD stuff    ********/
  27.  
  28.     numParams = paramPtr->paramCount;
  29.  
  30.     /*    Lock the parameter block down so we can safely refer to it:    */
  31.     MoveLockParams( paramPtr, numParams );
  32.  
  33.     /*    If any parameters WERE passed, go check to see if the first one is a ! or ?    */
  34.     if ( numParams > 0 )
  35.     {
  36.         paramString = (char *) *paramPtr->params[0];
  37.         paramLength = strlen( paramString );
  38.         if ( paramLength == 1 )
  39.         {
  40.             paramChar = *paramString;
  41.             switch ( paramChar )
  42.             {
  43.                 case '!':
  44.                     ReturnMessage( paramPtr, "\pCapsLock XFCN ©1995 Theron Trowbridge" );
  45.                     return;
  46.                     break;
  47.                 case '?':
  48.                 default:
  49.                     ReturnMessage( paramPtr, "\pSyntax is: \"CapsLock()\"" );
  50.                     return;
  51.                     break;
  52.             }
  53.         }
  54.     }
  55.     
  56.     if ( CapsLockIsDown() )
  57.         ReturnMessage( paramPtr, "\pdown" );
  58.     else
  59.         ReturnMessage( paramPtr, "\pup" );
  60.  
  61.     return;
  62. }
  63.  
  64. Boolean    CapsLockIsDown( void )
  65. {
  66.     KeyMap        testKeyMap;
  67.     
  68.     GetKeys( testKeyMap );
  69.     
  70.     if ( BitTst( &testKeyMap, 62 ) )
  71.         return( true );
  72.     else
  73.         return( false );
  74. }